package data;
import java.lang.reflect.Type;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;


public class LoginResponse extends Response {
	private int mUserId;
	private String mMessage = "";
	private CompanyInfo mCompany = new CompanyInfo();
	private boolean mSuperUser = false;
	
	public LoginResponse() {
	}
	
	public LoginResponse(int exitCode, int userId, String message, CompanyInfo company) {
		mExitCode = exitCode;
		mUserId = userId;
		mMessage = message;
		mCompany = company;
	}
	
	public LoginResponse(int exitCode, int userId, String message, boolean superUser, String name, String address1, String address2, String contact, int image) {
		mExitCode = exitCode;
		mUserId = userId;
		mMessage = message;
		mSuperUser = superUser;
		mCompany = new CompanyInfo(name, address1, address2, contact, image);
	}

	public String getMessage() {
		return mMessage;
	}
	
	public int getUserId() {
		return mUserId;
	}
	
	public CompanyInfo getCompanyInfo() {
		return mCompany;
	}
	
	public boolean isSuperUser() {
		return mSuperUser;
	}

	public final static JsonDeserializer<LoginResponse> deserializer = new JsonDeserializer<LoginResponse>() {

		@Override
		public LoginResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
				throws JsonParseException {
			
			int exitCode = json.getAsJsonObject().get("exitCode").getAsInt();
			int userId = json.getAsJsonObject().get("userId").getAsInt();
			String message = json.getAsJsonObject().get("message").getAsString();
			int superUser = json.getAsJsonObject().get("superUser").getAsInt();
			String name = json.getAsJsonObject().get("name").getAsString();
			String address1 = json.getAsJsonObject().get("address1").getAsString();
			String address2 = json.getAsJsonObject().get("address2").getAsString();
			String contact = json.getAsJsonObject().get("contact").getAsString();
			int image = json.getAsJsonObject().get("image").getAsInt();
            return new LoginResponse(exitCode, userId, message, superUser == 1, name, address1, address2, contact, image);
		}
	};
	
}